package com.test.Timer;

import java.text.SimpleDateFormat;
import java.util.TimerTask;

/**
 * Created by wangyg 
 * on 2017/6/2 17:07
 */
public class DefaultTimerTask extends TimerTask {
	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	private String name;
	private int count = 0;

	public DefaultTimerTask(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public void run() {
		if (count < 10) {
			System.out.println("当前count值为:" + count);
			System.out.println("当前TaskName:" + name + ";当前时间：" + sdf.format(System.currentTimeMillis()));

		} else {
			cancel();
			System.out.println("Task is over");
		}
		count++;
	}

}
